﻿<?php
	
	$name = trim($_POST['author']);
	$email = $_POST['email'];
	$subject = $_POST['subject'];
	$message = $_POST['message'];
	
	$site_owners_email = 'nirav.shah83@gmail.com'; // Replace this with your own email address
	$site_owners_name = 'Nirav Shah'; // Replace with your name
	
	if (strlen($name) < 2) {
		$error['name'] = "Please enter your name";	
	}
	
	if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
		$error['email'] = "Please enter a valid email address";	
	}
	/* Remove following comment if you want the subject field to be required */
	/* if (strlen($subject) < 2){
		$error['subject'] = "Please specify subject";
	} 
	
	if (strlen($message) < 3) {
		$error['message'] = "Please specify the message";
	}*/
	
	if (!$error) {
		
		//require_once('PHPMailer/class.phpmailer.php');
		require_once($_SERVER['DOCUMENT_ROOT'].'/lib/phpmailer/class.phpmailer.php');
		$mail = new PHPMailer();
		
		$mail->From = $email;
		$mail->FromName = $name;
		$mail->Subject = $subject;
		$mail->AddAddress($site_owners_email, $site_owners_name);
		$mail->Body = $message;
		
		$mail->Send();
		
		echo "<span class='success'> Thank you for your feedback, " . $name . ". We've received your email. We'll be in touch as soon as possble! </span>"; // You can replace this lines with your own text but DO NOT CHANGE TAGS
		
	}
	else {

		$response = (isset($error['name'])) ? "<span class='error'>" . $error['name'] . "</span> \n" : null;
		$response .= (isset($error['email'])) ? "<span class='error'>" . $error['email'] . "</span> \n" : null;
		$response .= (isset($error['subject'])) ? "<span class='error'>" . $error['subject'] . "</span>" : null;
		$response .= (isset($error['message'])) ? "<span class='error'>" . $error['message'] . "</span>" : null;
		
		echo $response;
	}

?>